<template>
  <div>
    <div>
      <van-nav-bar left-arrow @click-left="$router.go(-1)" />
    </div>
    <!--注册表单-->
    <div class="reg_user">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="username"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="email"
          type="email"
          name="email"
          label="邮箱"
          placeholder="邮箱"
          :rules="[{ required: true, message: '请填写邮箱' }]"
        />
        <van-field
          v-model="phone"
          type="phone"
          name="phone"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >注册</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { Dialog } from 'vant';
import {reg} from "@/api"
export default {
  data() {
    return {
        username: "",
        password: "",
        email: "",
        phone: "",
    };
  },
  methods: {
    async onSubmit(values) { 
      let {data}=await reg(values)
      if(data.code==-1){
        return
      }
      alert(data.msg+"去登录吗")
      this.$router.push({path:'/Login'})
    },
  },
};
</script>

<style lang="less" scoped>
.reg_user {
  width: 80%;
  margin: 0 auto;
  padding: 10px;
  margin-top: 3rem;
  .van-field {
    margin-top: 20px;
    border: 1px solid #ccc;
  }
}
</style>
